//======================================================================
/// COPYRIGHT MorningCoreTech CO.,LTD
/// @file        ue_tx_pucch_gen_fix.cpp
/// @brief       This function performs PUCCH symbol link Gen Proc
/// @author      cuiyuping
/// @param [IN]	     SimParam		               Input  Parameter .
/// @param [OUT]	 FreqData		               FreqData
  

/// @par History
/// -
///       Date|       Author|        Version|        DESCRIPTION
/// ----------|-------------|---------------|-------------------
/// 2022-10-20|   cuiyuping |          0.0.1|            created
//======================================================================

#include "ue_tx_pucch_gen_fix.h"
#include <math.h>


void ue_tx_pucch_gen_fix(
    IN stULParamTable *SimParam,
    OUT cmplx_t    *SRP_SC15_BE_Op
)
{
	int8 *BRP_UCI_Op ;	
	cmplx_frN *SRP_SC15_BE_Op_Fix;
	cmplx_frN *SubFrameOp[MAXSYMNUM];
	double  ConstN1, ConstN5;
	uint16 SubFrameNum = 1, s_idx, iSym;
	uint64  k;

	 
	BRP_UCI_Op = (int8 *)malloc((MAX_PUSCH_TTI_LEN) * sizeof(int8));
	memset(BRP_UCI_Op, 0, (MAX_PUSCH_TTI_LEN) * sizeof(int8));

	for (iSym = 0; iSym < MAXSYMNUM; iSym++)
	{
		SubFrameOp[iSym] = (cmplx_frN *)malloc((PUCCH_Max_RE) * sizeof(cmplx_frN));
		memset(SubFrameOp[iSym], 0, (PUCCH_Max_RE) * sizeof(cmplx_frN));
	}

	SRP_SC15_BE_Op_Fix = (cmplx_frN *)malloc((MAX_PUSCH_TTI_LEN) * sizeof(cmplx_frN));
	memset(SRP_SC15_BE_Op_Fix, 0, (MAX_PUSCH_TTI_LEN) * sizeof(cmplx_frN));

	UCILenCulation(SimParam);

	//=======================Parameter Calculation============================//
	SRP_PUCCH_FE_ParamGen(SimParam);
	//=======================Bit Stream Gernaration ============================//
	ue_tx_pucch_bit_gen(SimParam,BRP_UCI_Op);
	
	//=======================Symbolic Level Processing============================//
	vFilePUCCHParamPrint(SimParam);

	for (s_idx =0; s_idx< SubFrameNum; s_idx++)
	{      

		SRP_Top_PUCCH_fix(SimParam,BRP_UCI_Op,SubFrameOp);
		ue_tx_pucch_srp_fix(SimParam,SubFrameOp, SRP_SC15_BE_Op_Fix);

	}

	ConstN1 = pow(2.0, 13);
	ConstN5 = SimParam->float_fix_dif;

	if (PUCCH_FORMAT_0 == SimParam->PUCCH_Format)
	{
		for (k = 0; k < MAX_PUSCH_TTI_LEN; k++)
		{
			SRP_SC15_BE_Op[k].re = fractN_2_real_t(SRP_SC15_BE_Op_Fix[k].re, ConstN1);
			SRP_SC15_BE_Op[k].im = fractN_2_real_t(SRP_SC15_BE_Op_Fix[k].im, ConstN1);
		}
	}
	else
	{
		for (k = 0; k < MAX_PUSCH_TTI_LEN; k++)
		{
			SRP_SC15_BE_Op[k].re = SRP_SC15_BE_Op_Fix[k].re/ConstN5;
			SRP_SC15_BE_Op[k].im = SRP_SC15_BE_Op_Fix[k].im/ConstN5;
		}
	}


	char cFileName[256] = { '\0' };
	char cFileAddr_re[256] = { '\0' };
	char cFileAddr_im[256] = { '\0' };
	sprintf(cFileName, "Result/PUCCHTestData/CASE%d", CASEIDX_PRINT);
	sprintf(cFileAddr_re, "%s/PUCCH_DateOut_Fix_re.dat", cFileName);
	sprintf(cFileAddr_im, "%s/PUCCH_DateOut_Fix_im.dat", cFileName);
	vFilePrintDataFixpQI_WX_Flt(cFileAddr_re, cFileAddr_im, SRP_SC15_BE_Op, MAX_PUSCH_TTI_LEN);

	for (iSym = 0; iSym < MAXSYMNUM; iSym++)
	{
		free(SubFrameOp[iSym]);
	}
	free(SRP_SC15_BE_Op_Fix);
	free(BRP_UCI_Op);
}





